{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.instrument import IRCMSSpreadOption\n",
    "from gs_quant.markets import PricingContext\n",
    "from gs_quant.markets.portfolio import Portfolio\n",
    "from gs_quant.risk import IRAnnualImpliedVol, Price\n",
    "from gs_quant.session import Environment, GsSession\n",
    "import pandas as pd\n",
    "\n",
    "pd.options.display.float_format = '{:,.4f}'.format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Instrument - IRCMSSpreadOption",
     "Portfolio - Nested Portfolios"
    ]
   },
   "outputs": [],
   "source": [
    "# define a set of pairs and option expiries\n",
    "pairs = [('5y', '2y'), ('10y', '2y')]\n",
    "expiries = ['3m', '6m', '1y', '2y', '5y', '10y']\n",
    "portfolios = Portfolio(\n",
    "    [\n",
    "        Portfolio(\n",
    "            [\n",
    "                IRCMSSpreadOption(\n",
    "                    termination_date=e,\n",
    "                    notional_currency='EUR',\n",
    "                    notional_amount=10000,\n",
    "                    index1_tenor=p[0],\n",
    "                    index2_tenor=p[1],\n",
    "                    name=e,\n",
    "                )\n",
    "                for e in expiries\n",
    "            ],\n",
    "            name=p,\n",
    "        )\n",
    "        for p in pairs\n",
    "    ]\n",
    ")\n",
    "\n",
    "# price our list of portfolios\n",
    "with PricingContext():\n",
    "    result_p = portfolios.calc(Price)\n",
    "    result_v = portfolios.calc(IRAnnualImpliedVol)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prices = result_p.to_frame()\n",
    "prices"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vols = result_v.to_frame() * 10000\n",
    "vols"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
